﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using br.com.SistemaChamados.Controller;
using br.com.SistemaChamados.Enum;
using br.com.SistemaChamados.Model;

public partial class Pages_UnitMain : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void gdvUnit_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.CommandArgument);
        switch (e.CommandName)
        {
            case "Exclude":
                br.com.SistemaChamados.Model.Unit unit = new br.com.SistemaChamados.Model.Unit();
                UnitController Controller = new UnitController();
                unit.Id = id;


                try
                {
                    if (Controller.DeleteUnit(unit) == EnumGenericState.GENERIC_STATE_SUCCESS)
                    {
                        Response.Write(@"<script language='javascript'>alert('Categoria de Chamado excluido com Sucesso!');</script>");
                    }
                    else
                    {
                        Response.Write(@"<script language='javascript'>alert('Ocorreu um erro durante a exclusão, por favor tente novamente!');</script>");
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(@"<script language='javascript'>alert('Ocorreu um erro na exclusão: <br>" + ex.Message +
                                       ".');</script>");
                    unit = null;
                }
                finally
                {
                    Response.Redirect("UnitMain.aspx");
                }

                break;

            case "Update":
                Session["id"] = id;
                Response.Redirect("UnitUpdate.aspx");
                break;
        }
    }
}